package Integer;

/**
 * Some usefull methods for handling integer matrix
 * 
 * @author Torbjoern Klatt
 */
public class Matrix {
    /**
     * Printing out an integer nXm-Matrix well structured using the standard
     * Out-Stream.
     * @param matrix as Integer nXm-Matrix
     */
    public static void printMatrix(int[][] matrix) {
        for(int i = 0; i < matrix.length; i++) {
            for(int j = 0; j < matrix[i].length; j++) {
                System.out.print(matrix[i][j] + "\t");
            }
            System.out.print("\n");
        }
    }
    
    /**
     * Adding two integer nXm-Matrix of same size. If they are not of the same
     * size it returns a Zero-Matrix.
     * @param matrixA as Integer nXm-Matrix
     * @param matrixB as Integer nXm-Matrix
     * @return int[][]
     */
    public static int[][] addTwoMatrix(int[][] matrixA, int[][] matrixB) {
        int[][] result = {{0}};
        int nA = matrixA.length, nB = matrixB.length;
        int mA = matrixA[0].length, mB = matrixB[0].length;
        if(nA == nB && mA == mB) {
            result = new int[nA][mA];
            for(int i = 0; i < nA; i++) {
                for(int j = 0; j < mA; j++) {
                    result[i][j] = matrixA[i][j] + matrixB[i][j];
                }
            }
        }
        return result;
    }
}
